package org.worthydots.access.jpa.dao;

import java.util.List;

import org.worthydots.access.jpa.entity.Train;

public class TrainDAOImpl extends DAOImpl implements TrainDAO {

	public TrainDAOImpl() {
		super();
	}

	public void saveTrain(Train train) {
		entityManager.getTransaction().begin();
		entityManager.merge(train);
		entityManager.getTransaction().commit();
	}

	public void saveTrainIfNotPresent(Train train) {
		Train trainInDB = getTrainByTrainNumber(train.getNumber());
		if (trainInDB == null)
			saveTrain(train);
	}

	public Train getTrainByTrainNumber(String trainNumber) {
		return entityManager.find(Train.class, trainNumber);
	}

	public List<Train> getAllTrains() {
		// TODO Auto-generated method stub
		return null;
	}
}
